<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  User: 黄星
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/common.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/question.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/ajax.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/utils.js"></script>
    <script type="text/javascript">
        /*手动交卷*/
        function manualFinishExam() {
            $.ajax({
                "url": "${pageContext.request.contextPath}/Index/manualFinishExam",
                "data": $('#exam').serialize(),    //将表单序列化
                "type": "post",
                "dataType": "text",
                "success": function (data, textStatus) {
                    if (data != null) {
                        if (isScore(data.trim(data))) {
                            alert("您的得分为：" + data);
                            parent.document.location.replace("${pageContext.request.contextPath}/StudentIndex/studentIndex");
                        } else {
                            if (data.indexOf('choice') > -1) {
                                alert("还有选择题未选");
                            } else if (data.indexOf('blank') > -1) {
                                alert("还有填空题未填");
                            } else if (data.indexOf('judge') > -1) {
                                alert("还有判断题未选");
                            }

                            var s = '#' + data;
                            ($(s)[0]).scrollIntoView(true);
                        }
                    }
                }
            });
        }

        /*自动交卷*/
        function autoFinishExam() {
            $.ajax({
                "url": "${pageContext.request.contextPath}/Index/autoFinishExam",
                "data": $('#exam').serialize(),    //将表单序列化
                "type": "post",
                "dataType": "text",
                "success": function (data, textStatus) {
                    if (data != null) {
                        if (isScore(data.trim(data))) {
                            alert("您的得分为：" + data);
                            parent.document.location.replace("${pageContext.request.contextPath}/StudentIndex/studentIndex");
                        }
                    }
                }
            });
        }
    </script>

</head>
<body>
<form action="${pageContext.request.contextPath}testgetanswer" id="exam">
    <div class="clearfix question_page">
        <%--选择题显示开始--%>
        <div class="left question_type">
            选择题
        </div>
        <c:forEach items="${ sessionScope.choiceQuestion}" var="cq" varStatus="vs">
            <%--选择题题目显示--%>
            <div id="choice${vs.count}" class="left question_topic">
                    ${vs.count}、${cq.topic}
            </div>
            <%--选择题答案显示--%>
            <div class="left question_answer">
                <c:forEach items="${sessionScope.choiceAnswer}" var="ca" begin="${vs.count-1}" end="${vs.count-1}">
                    <div class="left question_peranswer">
                        <c:forEach items="${ca}" var="a" varStatus="cs">
                            <%--显示答案前的ABCD序号--%>
                            <c:if test="${cs.count == 1}">A、</c:if>
                            <c:if test="${cs.count == 2}">B、</c:if>
                            <c:if test="${cs.count == 3}">C、</c:if>
                            <c:if test="${cs.count == 4}">D、</c:if>
                            <%--每个radio的value值提交到后台  用来判断与计算--%>
                            <input type="radio" name="answer${vs.count}"
                                   <c:if test="${cs.count == 1}">value="1"</c:if>
                                   <c:if test="${cs.count == 2}">value="2"</c:if>
                                   <c:if test="${cs.count == 3}">value="3"</c:if>
                                   <c:if test="${cs.count == 4}">value="4"</c:if>>${a}<br/>
                        </c:forEach>
                    </div>
                </c:forEach>
            </div>
        </c:forEach>
        <%--选择题显示结束--%>

        <%--填空题显示开始--%>
        <div class="left question_type" style="margin-top: 5%;">
            填空题
        </div>
        <c:forEach items="${ sessionScope.blankQuestion}" var="cq" varStatus="vs">

            <div id="blank${vs.count}" class="left question_topic" style="margin-top: 2%;">
                    <%--开始显示填空题题号--%>
                    ${vs.count}、
                    <%--结束显示填空题题号--%>
                <%--开始显示填空题题目--%>
                <c:forEach items="${topicSplit}" var="ts" begin="${vs.count-1}" end="${vs.count-1}">
                    <c:forEach items="${ts}" var="t" varStatus="bottomline">
                        ${t}
                        <c:if test="${bottomline.count == 1}">__________________</c:if>
                    </c:forEach>
                </c:forEach>
                <%--结束显示填空题题目--%>
            </div>
            <%--显示填空题的输入框--%>
            <div class="left question_answer" style="margin-top: 3%;margin-left: 5%;">
                <input type="text" name="blank${vs.count}" style="width: 95%;height: 35px;" placeholder="在此输入答案">
            </div>
        </c:forEach>
        <%--填空题显示结束--%>

        <%--判断题显示开始--%>
        <div class="left question_type" style="margin-top: 5%;">
            判断题
        </div>
        <c:forEach items="${ sessionScope.judgeQuestion}" var="jq" varStatus="vs">
            <div id="judge${vs.count}" class="left question_topic" style="margin-top: 2%;">
                    ${vs.count}、${jq.topic} <%--//显示题号以及题目--%><br/>
                <input type="radio" name="judge${vs.count}" value="yes">对<br/>
                <input type="radio" name="judge${vs.count}" value="no">错
            </div>
        </c:forEach>
        <%--判断题显示结束--%>

        <input id="manualFinish" type="button" value="手动提交" onclick="manualFinishExam()" style="display: none">
        <input id="autoFinish" type="button" value="自动提交" onclick="autoFinishExam()" style="display: none"><%--隐藏按钮--%>
    </div>

</form>
</body>
</html>
